﻿
    using Chain.BLL;
    using System;
    using System.Data;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public partial class GroupList : PageBase
    {


        private void GetGroupList()
        {
            SysGroup group = new SysGroup();
            string strSql = " 1=1";
            strSql = strSql + string.Format(" and (IsPublic = 'true' or CreateUserID in (select UserID from sysUser where UserShopID={0}))", base._UserShopID);
            DataTable dt = group.GetList(strSql).Tables[0];
            DataTable dtTree = dt.Clone();
            group.BuildGroupTree(dt, 0, 0, ref dtTree);
            this.gvGroupList.DataSource = dtTree;
            this.gvGroupList.DataBind();
            PageBase.BindSerialRepeater(this.gvGroupList, 0);
            this.SetAdminPer();
        }

        protected void gvGroupList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                this.GetGroupList();
            }
        }

        public void SetAdminPer()
        {
            foreach (RepeaterItem e in this.gvGroupList.Items)
            {
                if ((e.ItemType == ListItemType.Item) || (e.ItemType == ListItemType.AlternatingItem))
                {
                    HtmlAnchor hyGroupEdit = (HtmlAnchor) e.FindControl("hyGroupPermission");
                    HtmlAnchor hyGroupDelete = (HtmlAnchor) e.FindControl("hyGroupel");
                    Label lblGroupID = e.FindControl("lblGroupID") as Label;
                    Label lblParentIDStr = e.FindControl("lblParentIDStr") as Label;
                    Label lblIsPublic = e.FindControl("lblIsPublic") as Label;
                    Label lblCreateUserID = e.FindControl("lblCreateUserID") as Label;
                    if (lblGroupID.Text == "1")
                    {
                        hyGroupEdit.Visible = false;
                        hyGroupDelete.Visible = false;
                    }
                    if (lblParentIDStr.Text.IndexOf("/" + base._UserGroupID + "/") < 0)
                    {
                        hyGroupEdit.Visible = false;
                        hyGroupDelete.Visible = false;
                    }
                    if (!bool.Parse(lblIsPublic.Text) && (int.Parse(lblCreateUserID.Text) != base._UserID))
                    {
                        hyGroupEdit.Visible = false;
                        hyGroupDelete.Visible = false;
                    }
                }
            }
        }
    }


